package com.example.taximeter.mapper;

import com.example.taximeter.bean.*;
import org.apache.ibatis.jdbc.SQL;


public class ActivityMapperProvider {

    //查询所有计价器
    public String findTaximeterAll(TaximeterView taximeterView){
        return new SQL(){
            {
                SELECT("* ");
                FROM("taximeter");
                StringBuilder sb = new StringBuilder();
                sb.append("1=1");
                if(taximeterView.getFactname()!=null&&!taximeterView.getFactname().equals("")){
                    sb.append(" and fact_name like CONCAT(CONCAT('%','"+taximeterView.getFactname()+"'), '%')");
                }
                if(taximeterView.getJjqtype()!=null&&!taximeterView.getJjqtype().equals("")){
                    sb.append(" and jjq_type like CONCAT(CONCAT('%','"+taximeterView.getJjqtype()+"'), '%')");
                }
                if(taximeterView.getPricetype()!=null&&!taximeterView.getPricetype().equals("")){
                    sb.append(" and price_type like CONCAT(CONCAT('%','"+taximeterView.getPricetype()+"'), '%')");
                }
                if(taximeterView.getCompanyname()!=null&&!taximeterView.getCompanyname().equals("")){
                    sb.append(" and company_name like CONCAT(CONCAT('%','"+taximeterView.getCompanyname()+"'), '%')");
                }
                if(taximeterView.getCarno()!=null&&!taximeterView.getCarno().equals("")){
                    sb.append(" and car_no like CONCAT(CONCAT('%','"+taximeterView.getCarno()+"'), '%')");
                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString());
                }
                ORDER_BY("car_no desc");
            }
        }.toString();
    }

    //查询所有出租车
    public String findCarInfoAll(CarInfo carInfo){
        return new SQL(){
            {
                SELECT("* ");
                FROM("tab_in_car_info");
                StringBuilder sb = new StringBuilder();
                sb.append("1=1");
                if(carInfo.getCompanyname()!=null&&!carInfo.getCompanyname().equals("")){
                    sb.append(" and company_name like CONCAT(CONCAT('%','"+carInfo.getCompanyname()+"'), '%')");
                }
                if(carInfo.getCarno()!=null&&!carInfo.getCarno().equals("")){
                    sb.append(" and car_no like CONCAT(CONCAT('%','"+carInfo.getCarno()+"'), '%')");
                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString());
                }
                ORDER_BY("car_no desc");
            }
        }.toString();
    }

    //查询所有计价器
    public String findTaximeterList(TaximeterView taximeterView){
        return new SQL(){
            {
                SELECT("* ");
                FROM("taximeter");
                StringBuilder sb = new StringBuilder();
                if((taximeterView.getCompanyname()==null||taximeterView.getCompanyname().equals(""))&&(taximeterView.getCarno()==null||taximeterView.getCarno().equals(""))){
                    sb.append("1=1");
                }else {
                    sb.append("1=1");
                    if(taximeterView.getCompanyname()!=null&&!taximeterView.getCompanyname().equals("")){
                        sb.append(" and company_name like CONCAT(CONCAT('%','"+taximeterView.getCompanyname()+"'), '%')");
                    }
                    if(taximeterView.getCarno()!=null&&!taximeterView.getCarno().equals("")){
                        sb.append(" and car_no like CONCAT(CONCAT('%','"+taximeterView.getCarno()+"'), '%')");
                    }
                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString());
                }
                ORDER_BY("car_no desc");
            }
        }.toString();
    }

    //查询所有参数文件
    public String findParamFileAll(ParamFileView paramFileView){
        return new SQL(){
            {
                SELECT("id,fact_name,price_type ,jjq_type ,fact_id ,price_id ,jjq_type_id ,price_file_no ,file_name ,s_time ,traffic_check ,price_check ,write_user ,memo,version,fileid,metrology_check ");
                FROM("paramfile");
                StringBuilder sb = new StringBuilder();
                sb.append("1=1");
                if(paramFileView.getFactname()!=null&&!paramFileView.getFactname().equals("")){
                    sb.append(" and fact_name like CONCAT(CONCAT('%','"+paramFileView.getFactname()+"'), '%')");
                }
                if(paramFileView.getPricetype()!=null&&!paramFileView.getPricetype().equals("")){
                    sb.append(" and price_type like CONCAT(CONCAT('%','"+paramFileView.getPricetype()+"'), '%')");
                }
                if(paramFileView.getPricefileno()!=null&&!paramFileView.getPricefileno().equals("")){
                    sb.append(" and price_file_no like CONCAT(CONCAT('%','"+paramFileView.getPricefileno()+"'), '%')");
                }
                if(paramFileView.getStimel()!=null&&!paramFileView.getStimel().equals("")){
                    sb.append(" and s_time >= '"+paramFileView.getStimel()+"'");
                }
                if(paramFileView.getStimer()!=null&&!paramFileView.getStimer().equals("")){
                    sb.append(" and s_time <= '"+paramFileView.getStimer()+"'");
                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString());
                }
                ORDER_BY("s_time desc");
            }
        }.toString();
    }

    //查询所有查询界面的信息
    public String findSearchAll(Search search){
        return new SQL(){
            {
                SELECT("* ");
                FROM("search");
                StringBuilder sb = new StringBuilder();
                sb.append("1=1");
                if(search.getFactname()!=null&&!search.getFactname().equals("")){
                    sb.append(" and fact_name like CONCAT(CONCAT('%','"+search.getFactname()+"'), '%')");
                }
                if(search.getJjqtype()!=null&&!search.getJjqtype().equals("")){
                    sb.append(" and jjq_type like CONCAT(CONCAT('%','"+search.getJjqtype()+"'), '%')");
                }
                if(search.getPricetype()!=null&&!search.getPricetype().equals("")){
                    sb.append(" and price_type like CONCAT(CONCAT('%','"+search.getPricetype()+"'), '%')");
                }
                if(search.getCompanyname()!=null&&!search.getCompanyname().equals("")){
                    sb.append(" and company_name ='"+search.getCompanyname()+"'");
                }
                if(search.getCarno()!=null&&!search.getCarno().equals("")){
                    sb.append(" and car_no like CONCAT(CONCAT('%','"+search.getCarno()+"'), '%')");
                }
                if(search.getVersion()!=null&&!search.getVersion().equals("")){
                    sb.append(" and version like CONCAT(CONCAT('%','"+search.getVersion()+"'), '%')");
                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString());
                }
                ORDER_BY("car_no desc");
            }
        }.toString();
    }

    //查询所有用户
    public String findUserAll(UserView userView){
        return new SQL(){
            {
                SELECT("* ");
                FROM("user");
                StringBuilder sb = new StringBuilder();
                sb.append("1=1");
                if(userView.getUsername()!=null&&!userView.getUsername().equals("")){
                    sb.append(" and user_name like CONCAT(CONCAT('%','"+userView.getUsername()+"'), '%')");
                }
                if(userView.getFullname()!=null&&!userView.getFullname().equals("")){
                    sb.append(" and full_name like CONCAT(CONCAT('%','"+userView.getFullname()+"'), '%')");
                }
                if(userView.getUserstat()!=null&&!userView.getUserstat().equals("")){
                    sb.append(" and user_stat = '"+userView.getUserstat()+"'");
                }
//                if(user.getUserexp()!=null&&!user.getUserexp().equals("")){
//                    sb.append(" and user_exp like CONCAT(CONCAT('%','"+user.getUserexp()+"'), '%')");
//                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString());
                }
                ORDER_BY("user_name desc");
            }
        }.toString();
    }

    //查询所有用户
    public String findRoleAll(Role role){
        return new SQL(){
            {
                SELECT("* ");
                FROM("tab_roles");
                StringBuilder sb = new StringBuilder();
                sb.append("1=1");
                if(role.getRolename()!=null&&!role.getRolename().equals("")){
                    sb.append(" and role_name like CONCAT(CONCAT('%','"+role.getRolename()+"'), '%')");
                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString());
                }
                ORDER_BY("role_name desc");
            }
        }.toString();
    }

    //查询所有出租车公司
    public String findCompanyAll(Company company){
        return new SQL(){
            {
                SELECT("* ");
                FROM("tab_dict_taxi_company");
                StringBuilder sb = new StringBuilder();
                sb.append("1=1");
                if(company.getCompanyname()!=null&&!company.getCompanyname().equals("")){
                    sb.append(" and company_name like CONCAT(CONCAT('%','"+company.getCompanyname()+"'), '%')");
                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString());
                }
                ORDER_BY("company_name desc");
            }
        }.toString();
    }

    //查询所有计价器厂商
    public String findFactAll(Fact fact){
        return new SQL(){
            {
                SELECT("* ");
                FROM("tab_dict_jjq_fact");
                StringBuilder sb = new StringBuilder();
                sb.append("1=1");
                if(fact.getFactname()!=null&&!fact.getFactname().equals("")){
                    sb.append(" and fact_name like CONCAT(CONCAT('%','"+fact.getFactname()+"'), '%')");
                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString());
                }
                ORDER_BY("fact_name desc");
            }
        }.toString();
    }

    //查询所有计价器型号
    public String findTaximeterTypeAll(TaximeterTypeView taximeterTypeView){
        return new SQL(){
            {
                SELECT("* ");
                FROM("jjqtype");
                StringBuilder sb = new StringBuilder();
                sb.append("1=1");
                if(taximeterTypeView.getJjqtype()!=null&&!taximeterTypeView.getJjqtype().equals("")){
                    sb.append(" and jjq_type like CONCAT(CONCAT('%','"+taximeterTypeView.getJjqtype()+"'), '%')");
                }
                if(taximeterTypeView.getFactname()!=null&&!taximeterTypeView.getFactname().equals("")){
                    sb.append(" and fact_name like CONCAT(CONCAT('%','"+taximeterTypeView.getFactname()+"'), '%')");
                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString());
                }
                ORDER_BY("jjq_type desc");
            }
        }.toString();
    }

    //查询所有价格类别
    public String findPriceAll(Price price){
        return new SQL(){
            {
                SELECT("* ");
                FROM("tab_dict_price_type");
                StringBuilder sb = new StringBuilder();
                sb.append("1=1");
                if(price.getPricetype()!=null&&!price.getPricetype().equals("")){
                    sb.append(" and price_type like CONCAT(CONCAT('%','"+price.getPricetype()+"'), '%')");
                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString());
                }
                ORDER_BY("price_type desc");
            }
        }.toString();
    }

    //查询所有计价器厂商
    public String findParamFileLogAll(ParamFileLog paramFileLog){
        return new SQL(){
            {
                SELECT("* ");
                FROM("paramfilelog");
                StringBuilder sb = new StringBuilder();
                sb.append("1=1");
                if(paramFileLog.getParamid()!=null&&!paramFileLog.getParamid().equals("")){
                    sb.append(" and param_id = '"+paramFileLog.getParamid()+"'");
                }
                if(paramFileLog.getUsername()!=null&&!paramFileLog.getUsername().equals("")){
                    sb.append(" and user_name like CONCAT(CONCAT('%','"+paramFileLog.getUsername()+"'), '%')");
                }
                if(paramFileLog.getOpertype()!=null&&!paramFileLog.getOpertype().equals("")){
                    sb.append(" and oper_type like CONCAT(CONCAT('%','"+paramFileLog.getOpertype()+"'), '%')");
                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString());
                }
                ORDER_BY("oper_time desc");
            }
        }.toString();
    }

    //查询升级记录列表
    public String findUpdateRecordAll(UpdateRecord updateRecord){
        return new SQL(){
            {
                SELECT("* ");
                FROM("tab_log_update");
                StringBuilder sb = new StringBuilder();
                sb.append("1=1");
                if(updateRecord.getCarno()!=null&&!updateRecord.getCarno().equals("")){
                    sb.append(" and car_no like CONCAT(CONCAT('%','"+updateRecord.getCarno()+"'), '%')");
                }
                if(updateRecord.getStartime()!=null&&!updateRecord.getStartime().equals("")){
                    sb.append(" and start_time ='"+updateRecord.getStartime()+"'");
                }
                if(updateRecord.getVersion()!=null&&!updateRecord.getVersion().equals("")){
                    sb.append(" and version like CONCAT(CONCAT('%','"+updateRecord.getVersion()+"'), '%')");
                }
                if(updateRecord.getEndtime()!=null&&!updateRecord.getEndtime().equals("")){
                    sb.append(" and end_time ='"+updateRecord.getEndtime()+"'");
                }
                if(!sb.toString().equals("")){
                    WHERE(sb.toString());
                }
                ORDER_BY("car_no desc");
            }
        }.toString();
    }

}
